package com.xjgc.eip.panel.controller;


import java.text.ParseException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.jeecg.common.api.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xjgc.common.entity.ReturnResult;
import com.xjgc.common.utils.DateUtil;
import com.xjgc.common.utils.TransNoUitl;
import com.xjgc.eip.panel.entity.ZxjEipScdd;
import com.xjgc.eip.panel.service.ZxjEipScddService;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wxy
 * @since 2019-11-08
 */
@RestController
@RequestMapping("/zxjEipScdd")
public class ZxjEipScddController {
    @Autowired
    private ZxjEipScddService zxjEipScddService;
    @RequestMapping("productOrder")
    public ReturnResult productOrder(){
        ZxjEipScdd zxjEipScdd=new ZxjEipScdd();
        zxjEipScdd.setIoflag("0");
        QueryWrapper<ZxjEipScdd> queryWrapper = new QueryWrapper<>();
        queryWrapper.setEntity(zxjEipScdd);
        List<ZxjEipScdd> list=zxjEipScddService.list(queryWrapper);
        ReturnResult returnResult = new ReturnResult();
        returnResult.setData(list);
        String orisys="0";
        String transno="";
        String operatetype="add";
        for (ZxjEipScdd zes:list) {
            //header数据
            if ("0".equals(zes.getStatus())){
                transno= TransNoUitl.genTransNo();
            }else if ("1".equals(zes.getStatus())){
                transno= TransNoUitl.genTransNo();
                operatetype="update";
            }
            //body数据  就是zex
            //TODO   调用接口推送数据
            //TODO   根据返回状态  status 修改推送结果
        }
        return returnResult;
    }

    public List<ZxjEipScdd> getNo(){
        QueryWrapper<ZxjEipScdd> queryWrapper = new QueryWrapper<>();
        queryWrapper.ne("supervision_flag","1");
        List<ZxjEipScdd> list = zxjEipScddService.list(queryWrapper);
        return list;
    }
    @GetMapping(value="/list")
    public Result<IPage<ZxjEipScdd>> queryPgList(ZxjEipScdd zxjEipScdd,
                                                   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                                   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize) {
        Result<IPage<ZxjEipScdd>> result = new Result<IPage<ZxjEipScdd>>();
        Page<ZxjEipScdd> page = new Page<ZxjEipScdd>(pageNo,pageSize);
        QueryWrapper<ZxjEipScdd> queryWrapper = new QueryWrapper<ZxjEipScdd>(zxjEipScdd);
        IPage<ZxjEipScdd> pageList = zxjEipScddService.page(page,queryWrapper);
        result.setSuccess(true);
        result.setResult(pageList);
        return result;
    }

    /**
     * 根据主键查询生产订单信息
     * @param zxjEipScdd
     * @return
     */
    @GetMapping(value="/detail")
    public Result<ZxjEipScdd> detail(ZxjEipScdd zxjEipScdd) {
        Result<ZxjEipScdd> result = new Result<ZxjEipScdd>();
        ZxjEipScdd zxjscdd = zxjEipScddService.getById(zxjEipScdd.getOrderId());
        result.setSuccess(true);
        result.setResult(zxjscdd);
        return result;
    }
    @RequestMapping("getOrderCount")
    public Map getOrderCount() throws ParseException {
        //今天推送数量
        Map paramMap=new HashMap();
        paramMap.put("pushTime", DateUtil.today());
        Map totalMap=zxjEipScddService.selectByTime(paramMap);
        paramMap.put("supplierCode","1000018466");
        Map baozhiMap=zxjEipScddService.selectByTime(paramMap);
        Map statistics=new HashMap();
        statistics.put("total",totalMap.get("salescount"));
        statistics.put("erci",baozhiMap.get("salescount"));
        int total=Integer.parseInt(totalMap.get("salescount").toString());
        int erci=Integer.parseInt(baozhiMap.get("salescount").toString());
        statistics.put("yibiao",total-erci);
        //昨天推送数量
        Map yParamMap=new HashMap();
        yParamMap.put("date",DateUtil.yestoday());
        Map yTotalMap=zxjEipScddService.selectByTime(yParamMap);
        yParamMap.put("supplierCode","1000018466");
        Map yBaozhiMap=zxjEipScddService.selectByTime(yParamMap);
        int yTotal=Integer.parseInt(yTotalMap.get("salescount").toString());
        int yErci=Integer.parseInt(yBaozhiMap.get("salescount").toString());
        if (yTotal !=0) {
            statistics.put("compareTotal",(total-yTotal)/yTotal);
            statistics.put("compareErci",(erci-yErci)/yTotal);
            statistics.put("compareYb",((total-erci)-(yTotal-yErci))/(yTotal-yErci));
        }else if(total!=0){
            statistics.put("compareTotal","100%");
            statistics.put("compareErci","100%");
            statistics.put("compareYb","100%");
        }
        return statistics;
    }
    @RequestMapping("selectByAreaTime")
    public Map selectByAreaTime() throws ParseException {
        return zxjEipScddService.selectByAreaTime();
    }
    @RequestMapping("selectByMonth")
    public Map selectByMonth() throws ParseException {
        return zxjEipScddService.selectByMonth();
    }
    @RequestMapping("selectByJidu")
    public List<Map> selectByJidu(){
        return zxjEipScddService.selectByJiDu();
    }
    @RequestMapping("selectByYear")
    public Map selectByYear(){
        return zxjEipScddService.selectByYear();
    }
}

